<?php
class Model {
    protected $db;
    protected $table;
    protected $container;
    
    public function __construct(Container $container) {
        $this->container = $container;
        $this->db = $container->make('Database');
    }
    
    public function findAll() {
        return $this->db->query("SELECT * FROM {$this->table}");
    }
    
    public function findById($id) {
        return $this->db->query("SELECT * FROM {$this->table} WHERE id = ?", [$id]);
    }
    
    public function create($data) {
        $columns = implode(', ', array_keys($data));
        $placeholders = implode(', ', array_fill(0, count($data), '?'));
        
        return $this->db->query("INSERT INTO {$this->table} ({$columns}) VALUES ({$placeholders})", array_values($data));
    }
    
    public function update($id, $data) {
        $setParts = [];
        foreach (array_keys($data) as $column) {
            $setParts[] = "{$column} = ?";
        }
        $setClause = implode(', ', $setParts);
        
        $values = array_values($data);
        $values[] = $id;
        
        return $this->db->query("UPDATE {$this->table} SET {$setClause} WHERE id = ?", $values);
    }
    
    public function delete($id) {
        return $this->db->query("DELETE FROM {$this->table} WHERE id = ?", [$id]);
    }
}
?>